<template>
  <div class="ticket">
    <x-header>管线设施信息
      <div href="javascript:;" class="headerAdd" @click="bindHeaderAdd">
        <img src="../../assets/img/securityCheckImg/addHeader.png" alt="">
      </div>
    </x-header>
<!-- {{FACILITY_MODEL_LIST}} -->
    <div class="ticketContent contractContent" v-for="(item, index) in dataList" :key="index" @click="facilitiesClick($event,item)">
      <div class="information-item">
        <div class="information-item-title">设施编号</div>
        <div class="information-item-answer">{{ item.FACILITY_NO }}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">设施名称</div>
        <div class="information-item-answer">{{ item.FACILITY_NAME }}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">性质/分类</div><!-- 问题 -->
        <div class="information-item-answer">/{{item.FACILITY_CODE_NAME}}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">上级设施</div>
        <div class="information-item-answer">{{item.P_FACILITY_ID_NAME}}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">地理位置</div>
        <div class="information-item-answer">{{item.ADDR_POSITION}}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">规格型号/材料形式</div>
        <div class="information-item-answer">{{item.FACILITY_MODEL_NAME}}/{{item.FACILITY_QUALITY_NAME}}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">连接方式/安装方式</div>
        <div class="information-item-answer">{{item.CONNECTION_MODE_NAME}}/{{item.INSTALL_MODE_NAME}}</div>
      </div>
      <div class="information-item">
        <div class="information-item-title">安装位置/当前状态</div>
        <div class="information-item-answer">/{{ item.CURRENT_STATE_NAME }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { XHeader } from "vux";
import Vue from "vue";
import { sqlQuery } from "@/utils/sqlOperation";
export default {
  data() {
    return {
      dataList: [],
      FACILITY_QUALITY_LIST: [],
      FACILITY_QUALITY: [],
      FACILITY_MODEL_LIST: [],
      FACILITY_MODEL: [],
      CONNECTION_MODE_LIST: [],
      FACILITY_CODE_LIST: [],
      INSTALL_MODE_LIST: [],
      CURRENT_STATE_LIST: [],
      P_FACILITY_ID_LIST: [],
      CONS_NO: ""
    };
  },
  components: {
    XHeader
  },
  methods: {
    bindHeaderAdd() {
      this.$router.push({
        path: "/facilitiesMaintain?CONS_NO=" + this.CONS_NO
      });
    },
    callback(str, msg) {
      const _this = this;
      console.log(11111111111111111,str, msg);
      console.log(_this.P_FACILITY_ID_LIST);
      switch (str) {
        case "change":
          const msgData = msg.map(function(item) {
            // 性质,分类
            for (let i in _this.FACILITY_QUALITY_LIST) {
              if (
                _this.FACILITY_QUALITY_LIST[i].value == item.FACILITY_QUALITY
              ) {
                item.FACILITY_QUALITY_NAME =
                  _this.FACILITY_QUALITY_LIST[i].name;
              }
            }
            for (let i in _this.FACILITY_CODE_LIST) {
              if (_this.FACILITY_CODE_LIST[i].value == item.FACILITY_CODE) {
                item.FACILITY_CODE_NAME = _this.FACILITY_CODE_LIST[i].name;
              }
            }
            // 上级设施
            for (let i in _this.P_FACILITY_ID_LIST) {
              if (_this.P_FACILITY_ID_LIST[i].value == item.P_M_CID) {
                item.P_FACILITY_ID_NAME = _this.P_FACILITY_ID_LIST[i].name;
              }
            }
            // 规格型号/材料形式
            for (let i in _this.FACILITY_MODEL_LIST) {
              if (_this.FACILITY_MODEL_LIST[i].value == item.FACILITY_MODEL) {
                item.FACILITY_MODEL_NAME = _this.FACILITY_MODEL_LIST[i].name;
              }
            }
            for (let i in _this.FACILITY_MODEL_LIST) {
              if (_this.FACILITY_MODEL_LIST[i].value == item.FACILITY_MODEL) {
                item.FACILITY_MODEL_NAME = _this.FACILITY_MODEL_LIST[i].name;
              }
            }
            //链接方式
            for (let i in _this.CONNECTION_MODE_LIST) {
              if (_this.CONNECTION_MODE_LIST[i].value == item.CONNECTION_MODE) {
                item.CONNECTION_MODE_NAME = _this.CONNECTION_MODE_LIST[i].name;
              }
            }
            //安装方式
            for (let i in _this.INSTALL_MODE_LIST) {
              if (_this.INSTALL_MODE_LIST[i].value == item.INSTALL_MODE) {
                item.INSTALL_MODE_NAME = _this.INSTALL_MODE_LIST[i].name;
              }
            }
            //当前状态
            for (let i in _this.CURRENT_STATE_LIST) {
              if (_this.CURRENT_STATE_LIST[i].value == item.CURRENT_STATE) {
                item.CURRENT_STATE_NAME = _this.CURRENT_STATE_LIST[i].name;
              }
            }
            return item;
          });
          Vue.set(_this, "dataList", msgData);
          break;
        case "noChange":
          const msgData1 = msg.map(function(item) {
            for (let i in _this.FACILITY_QUALITY_LIST) {
              if (
                _this.FACILITY_QUALITY_LIST[i].value == item.FACILITY_QUALITY
              ) {
                item.FACILITY_QUALITY_NAME =
                  _this.FACILITY_QUALITY_LIST[i].name;
              }
            }
            for (let i in _this.FACILITY_CODE_LIST) {
              if (_this.FACILITY_CODE_LIST[i].value == item.FACILITY_CODE) {
                item.FACILITY_CODE_NAME = _this.FACILITY_CODE_LIST[i].name;
              }
            }
            // 上级设施
            for (let i in _this.P_FACILITY_ID_LIST) {
              if (_this.P_FACILITY_ID_LIST[i].value == item.P_M_CID) {
                item.P_FACILITY_ID_NAME = _this.P_FACILITY_ID_LIST[i].name;
              }
            }
            // 规格型号/材料形式
            for (let i in _this.FACILITY_MODEL_LIST) {
              if (_this.FACILITY_MODEL_LIST[i].value == item.FACILITY_MODEL) {
                item.FACILITY_MODEL_NAME = _this.FACILITY_MODEL_LIST[i].name;
              }
            }
            for (let i in _this.FACILITY_MODEL_LIST) {
              if (_this.FACILITY_MODEL_LIST[i].value == item.FACILITY_MODEL) {
                item.FACILITY_MODEL_NAME = _this.FACILITY_MODEL_LIST[i].name;
              }
            }
            //链接方式
            for (let i in _this.CONNECTION_MODE_LIST) {
              if (_this.CONNECTION_MODE_LIST[i].value == item.CONNECTION_MODE) {
                item.CONNECTION_MODE_NAME = _this.CONNECTION_MODE_LIST[i].name;
              }
            }
            //安装方式
            for (let i in _this.INSTALL_MODE_LIST) {
              if (_this.INSTALL_MODE_LIST[i].value == item.INSTALL_MODE) {
                item.INSTALL_MODE_NAME = _this.INSTALL_MODE_LIST[i].name;
              }
            }
            //当前状态
            for (let i in _this.CURRENT_STATE_LIST) {
              if (_this.CURRENT_STATE_LIST[i].value == item.CURRENT_STATE) {
                item.CURRENT_STATE_NAME = _this.CURRENT_STATE_LIST[i].name;
              }
            }
            return item;
          });
          Vue.set(this, "dataList", this.dataList.concat(msgData1));
          break;
        default:
          break;
      }
    },
    facilitiesClick(event, item) {
      this.$router.push({
        path:
          "/facilitiesMaintain?item=" + JSON.stringify(item) + "&change_type=2"
      });
    },
    facilityCallback(str, msg) {
      switch (str) {
        case "change":
          const P_FACILITY_ID_LIST = msg.map(item => {
            return {
              name: item.FACILITY_NAME + "_" + item.ADDR_POSITION,
              value: item.M_CID
            };
          });
          Vue.set(this, "P_FACILITY_ID_LIST", P_FACILITY_ID_LIST);
          break;
        case "noChange":
          const P_FACILITY_ID_LIST2 = msg.map(item => {
            return {
              name: item.FACILITY_NAME + "_" + item.ADDR_POSITION,
              value: item.M_CID
            };
          });
          Vue.set(
            this,
            "P_FACILITY_ID_LIST",
            this.P_FACILITY_ID_LIST.concat(P_FACILITY_ID_LIST2)
          );
          break;
        default:
          break;
      }
    }
  },
  mounted() {
    Vue.set(this, "CONS_NO", localStorage.getItem("CONS_NO"));
    // sqlQuery(this.CONS_NO, "NOTE_INFO", this.callback);

    const _that = this;
    // 归属分类1
    AndroidApi.queryTableData(
      '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["mdmFacilityNature"]}',
      function(msg) {
        if (msg.resultCode === "9999") {
          const FACILITY_CODE_LIST = msg.result.map(item => {
            return {
              name: item.CODE_NAME,
              value: item.CODE_VALUE
            };
          });
          Vue.set(_that, "FACILITY_CODE_LIST", FACILITY_CODE_LIST);
        }
      }
    );
    // 规格型号3
    AndroidApi.queryTableData(
      '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["mdmFacilityModel"]}',
      function(msg) {
        if (msg.resultCode === "9999") {
          const FACILITY_MODEL_LIST = msg.result.map(item => {
            return {
              name: item.CODE_NAME,
              value: item.CODE_VALUE
            };
          });
          Vue.set(_that, "FACILITY_MODEL_LIST", FACILITY_MODEL_LIST);
        }
      }
    );
    // 材料形式4
    AndroidApi.queryTableData(
      '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["bpPartProperty"]}',
      function(msg) {
        if (msg.resultCode === "9999") {
          const FACILITY_QUALITY_LIST = msg.result.map(item => {
            return {
              name: item.CODE_NAME,
              value: item.CODE_VALUE
            };
          });
          Vue.set(_that, "FACILITY_QUALITY_LIST", FACILITY_QUALITY_LIST);
        }
      }
    );
    // 连接方式5
    AndroidApi.queryTableData(
      '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["mdmFacilityConmode"]}',
      function(msg) {
        if (msg.resultCode === "9999") {
          const CONNECTION_MODE_LIST = msg.result.map(item => {
            return {
              name: item.CODE_NAME,
              value: item.CODE_VALUE
            };
          });
          Vue.set(_that, "CONNECTION_MODE_LIST", CONNECTION_MODE_LIST);
        }
      }
    );
    // 安装方式6
    AndroidApi.queryTableData(
      '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["mdmFacilityInsmode"]}',
      function(msg) {
        if (msg.resultCode === "9999") {
          const INSTALL_MODE_LIST = msg.result.map(item => {
            return {
              name: item.CODE_NAME,
              value: item.CODE_VALUE
            };
          });
          Vue.set(_that, "INSTALL_MODE_LIST", INSTALL_MODE_LIST);
        }
      }
    );
    // 安装位置7
    // AndroidApi.queryTableData(
    //   '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["cdReCertType"]}',
    //   function(msg) {
    //     if (msg.resultCode === "9999") {
    //       const CERT_TYPE_LIST = msg.result.map(item => {
    //         return {
    //           name: item.CODE_NAME,
    //           value: item.CODE_VALUE
    //         };
    //       });
    //       Vue.set(_that, "CERT_TYPE_LIST", [CERT_TYPE_LIST]);
    //     }
    //   }
    // );
    // 当前位置8
    // AndroidApi.queryTableData(
    //   '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["cdReCertType"]}',
    //   function(msg) {
    //     if (msg.resultCode === "9999") {
    //       const CERT_TYPE_LIST = msg.result.map(item => {
    //         return {
    //           name: item.CODE_NAME,
    //           value: item.CODE_VALUE
    //         };
    //       });
    //       Vue.set(_that, "CERT_TYPE_LIST", [CERT_TYPE_LIST]);
    //     }
    //   }
    // );
    // 目前状态9
    AndroidApi.queryTableData(
      '{"whereClause":"select * from P_CODE where code_type= ?","whereArgs":["mdmFacilityState"]}',
      function(msg) {
        if (msg.resultCode === "9999") {
          const CURRENT_STATE_LIST = msg.result.map(item => {
            return {
              name: item.CODE_NAME,
              value: item.CODE_VALUE
            };
          });
          Vue.set(_that, "CURRENT_STATE_LIST", CURRENT_STATE_LIST);
        }
      }
    );
    sqlQuery(this.CONS_NO, "PIPE_VALVEINFO", this.facilityCallback);
    sqlQuery(this.CONS_NO, "PIPE_VALVEINFO", this.callback);
  }
};
</script>
<style scoped lang="less">
@import "../../assets/less/style.less";
</style>


